// pages/mytest/mytest.js
const app = getApp()
import http from "../../utils/http"
import util from "../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    safeTop: `40px`,
    info: '',
    config: '',
    orderTagInfos: [
      {
        title: '待付款',
        iconName: 'wallet',
        orderNum: 0,
        tabType: 'nopay',
        status: 1,
        imgUrl: '../../../../static/index/sdfk.png'
      },
      {
        title: '待发货',
        iconName: 'deliver',
        orderNum: 0,
        tabType: 'nosend',
        status: 1,
        imgUrl: '../../../../static/index/dfh.png'
      },
      {
        title: '待收货',
        iconName: 'package',
        orderNum: 0,
        tabType: 'notake',
        status: 1,
        imgUrl: '../../../../static/index/dsh.png'
      },
      {
        title: '待评价',
        iconName: 'comment',
        orderNum: 0,
        tabType: 'nocomment',
        status: 1,
        imgUrl: '../../../../static/index/sdpj.png'
      },
      {
        title: '售后',
        iconName: 'exchang',
        orderNum: 0,
        tabType: 'sales',
        status: 1,
        imgUrl: '../../../../static/index/ssh.png'
      },
    ],
    distributUserInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const high = app.globalData.safeTop + 20
    this.setData({
      safeTop: `${high}px`
    })

  },
  /**
 * 生命周期函数--监听页面显示
 */
  onShow() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 4
      })
    }
    this.getInfo();
    this.getDistributionUserInfo();
  },
  onLoadConfig(option) {
    this.setData({
      config: app.globalData.config
    })
  },
  toService() {
    // 服务接单 跳 师傅端服务端
    wx.navigateToMiniProgram({
      appId: 'wxb054a1c859d77708',
      envVersion: 'trial'
    })
  },
  toShop() {
    // 商家入驻 跳 商家端
    wx.navigateToMiniProgram({
      appId: 'wx4026ff1b9086ada9',
      envVersion: 'trial'
    })
  },
  login() {
    util.skip('/service/login/login')
  },
  skipShopping(e) {
    let url = e.currentTarget.dataset.url
    util.skip(url)
  },
  skip(e) {
    let url = e.currentTarget.dataset.url
    util.authSkip(url)
  },
  myOrder(e) {
    let type = e.currentTarget.dataset.type
    let active = e.currentTarget.dataset.active
    let num = this.data.info ? this.data.info.orderCount.unServiceCount : 0
    util.authSkip('/service/myorder/myorder?type=' + type + '&active=' + active + '&num=' + num)
  },
  getInfo() {
    if (!wx.getStorageSync('token')) return
    http.post('index/userindex', '', !this.data.info).then(res => {
      this.setData({
        info: res.data
      })
    })
  },
  getDistributionUserInfo(){
    http.post('/addons/shopro/user').then(res => {
      this.setData({
        distributUserInfo: res.data
      })
    })
  },

  //跳转意见反馈
  tofeedback() {
    wx.navigateTo({
      url: '/service/feedback/feedback',
    })
  },
  //跳转领券中心
  tocouponscenter() {
    wx.navigateTo({
      url: '/service/couponscenter/couponscenter',
    })
  },
  //跳转我的评论
  tomycomment() {
    wx.navigateTo({
      url: '/service/mycomment/mycomment',
    })
  },
  // 分销跳转
  distributionTap() {
    wx.navigateTo({
      url: '/service/distribution/distribution',
    })
  },
   // 新单待办跳转
  pendingOrderTap(){
    wx.reLaunch({
      url: '/service/pendingOrder/pendingOrder',
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(option) {
    let data = option.target.dataset.id; //取到传入的参数
    //来自页面按钮内的分享
    if(option.from === 'button'){

    }
    return {
      title: '分享',
      path: `pages/index/index?parent_user_id=${app.globalData.user.id || 0}`,
      imageUrl: '',
      success: () => {
          console.log('分享成功');
      },
      fail: () => {
          console.log('分享失败');
      },
    };
  },
  //商城订单管理跳转
  jumpNav(e) {
    const status = e.detail.tabType;

    if (status === 'sales') {
      // wx.navigateTo({ url: '/service/Order/after-service-list/index' });
      util.authSkip('/service/shoppingMall/Order/after-service-list/index')

    } else {
      util.authSkip('/service/shoppingMall/Order/order-list/index?status=' + status)
    }
  },
  //全部订单
  jumpAllOrder() {
    const status = 'all'
    util.authSkip('/service/shoppingMall/Order/order-list/index?status=' + status)

  },
})